package edu.tum.cs.i1.pse;

public class CipherWordSelectorDecorator implements Cipher {
	
	private Cipher decoratedCipher;
	
	public CipherWordSelectorDecorator (Cipher decorated) {
		this. decoratedCipher = decorated;
	}

	@Override
	public String encryptWord(String w, byte k) {
		StringBuffer result = new StringBuffer();
		MyIterator wIterator = new StringWordsIterator(w);
		
		while(wIterator.hasNext()) {
			result.append(decoratedCipher.encryptWord((String)wIterator.next(), k));
			result.append(" ");
		}
		
		return result.toString();
	}

	@Override
	public String decryptWord(String w, byte k) {
		StringBuffer result = new StringBuffer();
		MyIterator wIterator = new StringWordsIterator(w);
		
		while(wIterator.hasNext()) {
			result.append(decoratedCipher.decryptWord((String)wIterator.next(), k));
			result.append(" ");
		}
		
		return result.toString();
	}

}
